﻿using System;
using System.Windows.Forms;

namespace CXMLStudioIDE.Forms
{
    public partial class NewSolutionForm : Form
    {
        private MainForm frm_parent;

        public NewSolutionForm(Form parent)
        {
            InitializeComponent();
            frm_parent = parent as MainForm;
            frm_parent.EnabledMenuItem("menuItemCloseSolution", true);
            frm_parent.EnabledMenuItem("menuItemSaveSolution", true);
            frm_parent.EnabledMenuItem("menuItemSaveAll", true);
        }

        private void rbNewProject_CheckedChanged(object sender, EventArgs e)
        {
            if (rbNewProject.Checked)
            {
                btnOk.Text = "Next >>";
                if(txtSolutionName.Text.Length == 0 )
                    btnOk.Enabled = false;
            }
        }

        private void rbEmpty_CheckedChanged(object sender, EventArgs e)
        {
            if (rbEmpty.Checked) {
                btnOk.Text = "OK";
                btnOk.Enabled = true;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void lblTemplates_Click(object sender, EventArgs e)
        {

        }


       private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtSolutionName.Text.Length == 0)
            {
                MessageBox.Show(this,"Please enter a Solution name", "CXMLStudio",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            else {
                //First create a solution
                frm_parent.m_SolutionManager.CreateSolution(-1,txtSolutionName.Text);
                frm_parent.Text = txtSolutionName.Text + " - CXMLStudioIDE";

                if (rbNewProject.Checked)
                {
                    NewProjectForm npf = new NewProjectForm(frm_parent);
                    npf.Show();
                }
                else
                {
                    frm_parent.UpdateMainForm();
                }
                this.Close();
                this.Dispose();
                frm_parent.EnabledMenuItem("menuItemSolution", true);
                
            }
        }

       private void txtSolutionName_TextChanged(object sender, EventArgs e)
       {
           btnOk.Enabled = true;
       }


    }
}
